<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>现金卡密查询</title>
    <!--{include file='comm/comm_cal.tpl'}-->
    <!--{include file="comm/icheck.tpl"}-->
    <!--{include file='comm/comm_pic.tpl'}-->
</head>
<body>

<div class="container">

    <div class="comm_content">

            <div class="search-box">
                <div style="position:relative">
                    <form class="form-inline" id="search_form" onsubmit="return false;">
                        <table style="width:100%;">
                            <tbody>
                            <tr>
                                <td>
                                    <span>
                                        现金卡卡号：<input type="text"  class="form-control input-sm" name="card_no" id="card_no" style="width:150px;"/>
                                    </span>
                                    <span><input type="button" value="查询" id="searchBtn" class="btn btn-primary" onclick="card.search();" /></span>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>

            <table id="flex" style="display:none"></table>
            <br />
            <br />
            <table id="flex_bill_array" style="display:none"></table>



        </div>

</div>

<script type="text/javascript">

$("#flex_bill_array").flexigrid({
    url:"/invokingAjax-backend/company/card.ajax?operFlg=13",
    dataType: "json",
    colModel : [
        {display: "订单号", width : 150, align:"center"},
        {display: "订单状态", width : 150,align:"left"},
        {display: "退货单号", width : 300,align:"left"},
        {display: "退货状态", width : 300,align:"left"}
    ],
    height:'auto',
    title: '使用过的订单、退货单',
    striped:false,
    autoload: false,
    usepager: false,
    rp: 10,
    useRp: true,
    showTableToggleBtn: true
});


$("#flex").flexigrid({
    url:"/invokingAjax-backend/company/card.ajax?operFlg=11",
    dataType: "json",
    colModel : [
        {display: "操作", width : 150, align:"center"},
        {display: "现金卡卡号", width : 150,align:"left"},
        {display: "现金卡密码", width : 150,align:"left"},
        {display: "现金卡类型", width : 100,align:"left"},
        {display: "现金卡面值", width : 100,align:"center"},
        {display: "现金卡状态", width : 100,align:"center"},
        {display: "可使用次数", width : 140,align:"center"},
        {display: "已使用次数", width : 140,align:"center"},
        {display: "有效期开始日期", width : 150,align:"center"},
        {display: "有效期结束日期", width : 150,align:"center"}
    ],
    height:'auto',
    title: '现金卡信息',
    striped:false,
    autoload: false,
    usepager: false,
    rp: 10,
    nomsg : '现金卡不存在!',
    procmsg : '正在处理,请稍候 ...',
    useRp: true,
    showTableToggleBtn: true

});


var card ={

    authorization : false,//是否授权
    authorization_user : '',//授权人

    card_no:'',//现金卡号

    //头部 按条件查询
    search: function() {
        var card_no = $("#card_no").val();
        if( undefined == card_no || card_no == '')
        {
            E.alert('请输入现金卡号');
            return;
        }
        if(isNaN(card_no))
        {
            E.alert('现金卡号不正确,请重新输入');
            return;
        }


        card.card_no = card_no;
        if(!card.authorization)
        {
            card.check();
        }
        else
        {
            card.reload();
        }

    },

    //重新加载表格
    load: function() {
        $("#flex").flexReload();
    },
    reload : function() {

        var params = new Array();
        params.push(
                {
                    name : 'card_no',
                    value : card.card_no
                }
        );
        params.push(
                {
                    name : 'authorization_user' ,
                    value : card.authorization_user
                }
        );
        console.log(params);
        var dt = $('#search_form').serializeArray();
        //console.log(dt);

        $("#flex").flexOptions({params: params}).flexReload();
        $("#flex_bill_array").flexOptions({params: params}).flexReload();
    },
    //授权操作
    check:function(){
        html = '<form class="form-horizontal" role="form">';
        html += '<div class="form-group">';
        html += '<label for="auth_username" class="col-sm-2 control-label">用户名</label>';
        html += '<div class="col-sm-10">';
        html += '<input type="text" class="form-control" id="auth_username" placeholder="请输入用户名"></div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label for="auth_password" class="col-sm-2 control-label" autocomplete="off" node-type="password">密码</label>';
        html += '<div class="col-sm-10">';
        html += '<input type="text" class="form-control" id="auth_password" placeholder="请输入密码" autocomplete="off" onfocus="this.type=\'password\'"></div>';
        html += '</div>';
        html += '</form>';


        E.popup.open({
            title: '授权操作',
            content: html,
            css: 'width: 450px;',
            btnName: '授权',
            btnCall: "card.execute();"
        });

    },

    execute:function(){

        var username = $("#auth_username").val();
        var pwd = $("#auth_password").val();

        E.ajax_post({
            url: '/invokingAjax-comm/base/permission.ajax?operFlg=1',
            data: {
                userID:username,
                userPwd:pwd,
                permissionsID:70014
            },
            call: 'card.callBack'
        });

    },

    callBack:function( o ){
        if(o.code == 200){

            card.authorization = true;
            card.authorization_user = $("#auth_username").val();
            card.reload();
            E.alert('授权成功',2);
            E.popup.close();

        }else{
            E.alert(o.message );
        }
    },

    reset:function(cardNo,cardStatus)
    {
//        if(cardStatus == 1 || cardStatus == 2 || cardStatus== 3 || cardStatus == 4)
//        {
//            E.alert("现金卡"+cardNo+"还未到\"已发卡\"状态,不可重置");
//            return;
//        }
//
//        if(cardStatus == 5 )
//        {
//            E.alert("现金卡"+cardNo+"为\"已发卡\"状态,无需重置");
//            return;
//        }

        card.card_no = cardNo;
        E.confirm('是否重置现金卡'+cardNo+'状态至\'已发卡\'?','card.reset_submit');
    },

    reset_submit : function()
    {
        E.ajax_post({
            url: '/invokingAjax-backend/company/card.ajax?operFlg=12',
            data: {
                card_no:card.card_no,
                authorization_user : card.authorization_user
            },
            call: 'card.reset_callBack'
        });
    },
    reset_callBack : function ( o )
    {
        if(o.code == 200){
            card.reload();
            E.alert('现金卡重置成功',2);
            E.popup.close();
        }else{
            E.alert(o.message );
        }

    },

    return_view: {

        open: function( return_no, operFlg ) {

            E.ajax_get({
                url: '/invokingAjax-backend/bill/billReturn.ajax?operFlg=7&xjx=none',
                data: {
                    return_no: return_no
                },
                call: 'card.return_view.result'
            });

        },

        result: function( o ) {

            if (o.code == 200) {

                var return_obj = o.data;

                var html = '<div class="panel panel-default form-horizontal">';
                html += '<div class="panel-heading">退货单信息</div>';
                html += '<div class="panel-body">';

                html += '<div class="form-group">';
                html += '<label class="col-sm-2 control-label">退货单编号</label>';
                html += '<div class="col-sm-10">';
                html += '<p class="form-control-static">' + return_obj.return_no + '</p>';
                html += '</div>';
                html += '</div>';

                html += '<div class="form-group">';
                html += '<label class="col-sm-2 control-label">订单号</label>';
                html += '<div class="col-sm-10">';
                html += '<p class="form-control-static">' + return_obj.bill_code + '</p>';
                html += '</div>';
                html += '</div>';

                //add by 20141028 sunqiang FUN-BK-0012 退货单默认退货金额 start
                html += '<div class="form-group">';
                html += '<label class="col-sm-2 control-label">运费</label>';
                html += '<div class="col-sm-10">';
                html += '<p class="form-control-static">' + return_obj.deliver_feePaid + '</p>';
                html += '</div>';
                html += '</div>';
                //add by 20141028 sunqiang FUN-BK-0012 退货单默认退货金额 end
                if (return_obj.return_reason_2 == null || return_obj.return_reason_2 == 'null') {
                    return_obj.return_reason_2 = '';
                }

                html += '<div class="form-group">';
                html += '<label class="col-sm-2 control-label">退货原因</label>';
                html += '<div class="col-sm-3">';
                html += '<p class="form-control-static">' + return_obj.return_reason_1 + '</p>';
                html += '</div>';
                html += '<label class="col-sm-1 control-label">内容</label>';
                html += '<div class="col-sm-4">';
                html += '<p class="form-control-static">' + return_obj.return_reason_2 + '</p>';
                html += '</div>';
                html += '</div>';

                html += '<div class="form-group">';
                html += '<label class="col-sm-2 control-label">问题描述</label>';
                html += '<div class="col-sm-10">';
                html += '<p class="form-control-static">' + return_obj.return_memo + '</p>';
                html += '</div>';
                html += '</div>';

                html += '<div class="form-group">';
                html += '<label class="col-sm-2 control-label">商品返回方式</label>';
                html += '<div class="col-sm-10">';
                html += '<p class="form-control-static">' + return_obj.goods_return_type_name + '</p>';
                html += '</div>';
                html += '</div>';

                if(return_obj.coupon){
                    $.each(return_obj.coupon,function(key,value){
                        if(!E.isEmpty(value.coupon_code)){
                            html += '<div class="form-group">';
                            html += '<label class="col-sm-2 control-label">优惠券</label>';
                            html += '<div class="col-sm-10">';
                            html += '<p class="form-control-static">' + value.coupon_name + '('+ value.coupon_code +')' + '</p>';
                            html += '</div>';
                            html += '</div>';
                        }
                    });
                }
                if(return_obj.card){
                    $.each(return_obj.card,function(key,value){
                        if(!E.isEmpty(value.card_no)){
                            html += '<div class="form-group">';
                            html += '<label class="col-sm-2 control-label">现金卡</label>';
                            html += '<div class="col-sm-10">';
                            html += '<p class="form-control-static">' + value.card_name + '('+ value.card_no +')' + '</p>';
                            html += '</div>';
                            html += '</div>';
                        }
                    });
                }

                if(return_obj.pay){
                    $.each(return_obj.pay,function(key,value){
                        html += '<div class="form-group">';
                        html += '<label class="col-sm-2 control-label">'+value.payTypeName+'</label>';
                        html += '<div class="col-sm-10">';
                        html += '<p class="form-control-static">' + value.return_pay + '</p>';
                        html += '</div>';
                        html += '</div>';
                    });
                }

                if (return_obj.goods_return_type == 2) {
                    var addr = return_obj.pick_province + return_obj.pick_city + return_obj.pick_county + return_obj.pick_address;
                    html += '<div class="form-group">';
                    html += '<label class="col-sm-2 control-label">取货地址</label>';
                    html += '<div class="col-sm-10">';
                    html += '<p class="form-control-static">' + addr + '</p>';
                    html += '</div>';
                    html += '</div>';
                }

                html += '<div class="form-group">';
                html += '<label class="col-sm-2 control-label">联系人姓名</label>';
                html += '<div class="col-sm-10">';
                html += '<p class="form-control-static">' + return_obj.custName + '</p>';
                html += '</div>';
                html += '</div>';

                html += '<div class="form-group">';
                html += '<label class="col-sm-2 control-label">手机号码</label>';
                html += '<div class="col-sm-10">';
                html += '<p class="form-control-static">' + return_obj.mobile + '</p>';
                html += '</div>';
                html += '</div>';
                html += '</div>';
                html += '</div>';

                html += '<div class="panel panel-default">';
                html += '<div class="panel-heading">退货商品</div>';
                html += '<table class="table">';
                html += '<thead>';
                html += '<tr>';
                html += '<th width="180">商品编号</th>';
                html += '<th width="*">商品名称</th>';
                html += '<th width="100">规格</th>';
                html += '<th width="100">销售价</th>';
                html += '<th width="100">配件费</th>';
                html += '<th width="80">退货数量</th>';
                html += '</tr>';
                html += '</thead>';
                html += '<tbody>';
                $.each(return_obj.return_goods, function(k, v) {
                    html += '<tr>';
                    html += '<td>' + v.goodsID + '</td>';
                    html += '<td>' + v.goodsName + '</td>';
                    html += '<td>' + v.spec + '</td>';
                    //mod by 20141028 sunqiang FUN-BK-0012 退货单默认退货金额 start
                    html += '<td>' + v.goods_purchasePrice + '</td>';
                    html += '<td>' + v.buyMoney.toFixed(2) + '</td>';
                    //mod by 20141028 sunqiang FUN-BK-0012 退货单默认退货金额 end
                    html += '<td class="tac">' + v.goods_amount + '</td>';
                    html += '</tr>';
                });
                html += '</tbody>';
                html += '</table>';
                html += '</div>';

                E.popup.open({
                    title: '服务单详情',
                    content: html,
                    css: 'width: 800px;'
                });
            } else {
                E.alert(o.message);
            }

        }

    }



};

</script>

</body>
</html>